package co.com.smart.eagle.mapper;

import co.com.smart.eagle.entities.EagleSecurityApplications;
import co.com.smart.eagle.entities.EagleSecurityResources;
import co.com.smart.eagle.entities.EagleSecurityRoles;
import co.com.smart.eagle.entities.EagleSecurityUsers;
import co.com.smart.eagle.infrastructure.dto.AplicacionesDTO;
import co.com.smart.eagle.infrastructure.dto.RecursosDTO;
import co.com.smart.eagle.infrastructure.dto.RolesDTO;
import co.com.smart.eagle.infrastructure.dto.UsuariosDTO;

public class Mapper {
	
	public static RolesDTO mapperRoles(EagleSecurityRoles role){
		RolesDTO rol = new RolesDTO();
		rol.setDsRol(role.getIdrol());
		return rol;
	}
	
	public static EagleSecurityUsers mapperEntityUser(UsuariosDTO user){
		EagleSecurityUsers userreturn = new EagleSecurityUsers();
		userreturn.setUsername(user.getDsUser());
		userreturn.setPassword(user.getDsClave());
		return userreturn;
	}
	
	public static EagleSecurityRoles mapperEntityRol(RolesDTO rol){
		EagleSecurityRoles rolreturn = new EagleSecurityRoles();
		rolreturn.setIdrol(rol.getDsRol());
		return rolreturn;
	}
	
	public static AplicacionesDTO mapperAplicaciones(EagleSecurityApplications app){
		AplicacionesDTO appdto = new AplicacionesDTO();
		appdto.setDsAplicacion(app.getAplication());
		return appdto;
	}
	
	public static EagleSecurityApplications mapperEntityApplications(AplicacionesDTO app){
		EagleSecurityApplications appturn = new EagleSecurityApplications();
		appturn.setAplication(app.getDsAplicacion());
		return appturn;
	}
	
	public static RecursosDTO mapperResources(EagleSecurityResources resource){
		RecursosDTO resourcedto = new RecursosDTO();
		
		resourcedto.setIdresource(resource.getIdresource());
		resourcedto.setApplication(mapperAplicaciones(resource.getWlsSecurityApplications()));
		resourcedto.setRol(mapperRoles(resource.getWlsSecurityRole()));
		resourcedto.setAllowed(resource.getAllowed() == 0?true:false);
		resourcedto.setContextpath(resource.getContextpath());
		resourcedto.setUri(resource.getUri());
		
		return resourcedto;
	}
	
	public static EagleSecurityResources mapperEntityResources(RecursosDTO resource){
		EagleSecurityResources resourceReturn = new EagleSecurityResources();
		resourceReturn.setIdresource(resource.getIdresource());
		resourceReturn.setWlsSecurityApplications(mapperEntityApplications(resource.getApplication()));
		resourceReturn.setWlsSecurityRole(mapperEntityRol(resource.getRol()));
		resourceReturn.setAllowed(resource.getAllowed()?0:1);
		resourceReturn.setContextpath(resource.getContextpath());
		resourceReturn.setUri(resource.getUri());
		return resourceReturn;
	}

}
